package com.leezt.designpattern.creation.s01singleton;

import java.util.concurrent.atomic.AtomicLong;

/*
* implement ID generator with lazy way.
*/
public class LazyIdGenerator {
    private final AtomicLong id = new AtomicLong(0);
    private static LazyIdGenerator instance;
    private LazyIdGenerator(){}
    public static synchronized LazyIdGenerator getInstance() {
        if (null == instance) {
            instance = new LazyIdGenerator();
        }
        return instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }
}
